<template>
  <div class="box">
    <div class="search">
      <van-search v-model="value" placeholder="请输入小区或地址" >
        <template #left>
            <div class="city" @click="$router.push('/city')" >
              <span>{{ cityName }}</span>
              <span><van-icon name="play" size="1.1em" color="#7f7f80" style="transform:rotate(90deg)" /></span>
            </div>
          </template>
      </van-search>
       <div class="icon"><van-icon name="location-o"  /></div>
    </div>
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(item, index) in swiperImg" :key="index">
        <img :src="item" alt="" />
      </van-swipe-item>
    </van-swipe>
    <!-- 导航 -->
    <ul class="tab">
      <li>
        <img
          src=""
          alt=""
        />
        <div>整租</div>
      </li>

      <li>
        <img
          src=""
          alt=""
        />
        <div>合租</div>
      </li>

      <li @click="$router.push('/map')">
        <img
          src=""
          alt=""
        />
        <div>地图找房</div>
      </li>

      <li @click="$router.push('/rent/add')">
        <img
          src=""
          alt=""
        />
        <div>去出租</div>
      </li>
    </ul>
    <!-- 小组 -->
    <div>
      <div class="title">
        <span class="left zfxz">租房小组</span>
        <span class="right gd">更多</span>
      </div>
      <div>
        <van-row class="row">
          <van-col
            span="12"
            class="groupItem"
            v-for="item in groupList"
            :key="item.id"
          >
            <div class="img left">
              <img :src="item.imgSrc" alt="" />
            </div>
            <div class="rightgroup">
              <div class="groupText ">{{ item.title }}</div>
              <div class="groupText ">{{ item.desc }}</div>
            </div>
          </van-col>
        </van-row>
      </div>
    </div>
  </div>
</template>

<script>
import { getHouse } from '@/utils/stroage'

import { swiper, getGroupList } from '@/api/home'
export default {
  data () {
    return {
      swiperImg: [],
      groupList: [],
      value: '',
      cityName: '北京'
    }
  },
  async created () {
    const BJobj = { label: '北京', value: 'AREA|88cff55c-aaa4-e2e0', pinyin: 'beijing', short: 'bj' }
    const CityObj = JSON.parse(getHouse())
    console.log(CityObj)
    if (!CityObj) {
      this.cityName = BJobj.label
    } else {
      this.cityName = CityObj.label
    }

    // 轮播图
    const {
      data: { body }
    } = await swiper()
    body.forEach((item) => {
      this.swiperImg.push(`http://liufusong.top:8080${item.imgSrc}`)
    })
    // 轮播图结束
    // 导航
    const group = await getGroupList()
    this.groupList = group.data.body
    this.groupList.forEach((item) => {
      item.imgSrc = `http://liufusong.top:8080${item.imgSrc}`
    })
    console.log(this.groupList)
  },
  onSearch () {}
}
</script>

<style lang="less" scoped>

.my-swipe .van-swipe-item {
  height: 212px;
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  // background-color: #39a9ed;
  img {
    width: 100%;
    height: 100%;
  }
}
// 中间
.tab {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0;
  background-color: #ffffff;
  font-size: 14px;
  height: 100px;
  li {
    flex: 1;
    height: 87px;
    // background-color: red;
    text-align: center;
    img {
      width: 60px;
      display: inline-block;
    }
  }
}
.title {
  width: 100%;
  height: 50px;
  line-height: 50px;
  background-color: #f6f5f6;
  .zfxz {
    font-size: 15px;
    font-weight: 700;
    padding: 0 0 0 20px;
  }
  .gd {
    color: #787d82;
    padding: 0 10px 0 0;
  }
}
.left {
  float: left;
}
.right {
  float: right;
}
.row {
  background-color: #f6f5f6;
  // padding: 0 10px;
  height: 130px;
  // background-color: c;
  .groupItem {
    display: flex;
    // justify-content:;
    width: 170px;
    height: 55px;
    background-color: #fff;
    border-radius: 5px;
    margin-left:12px;
    margin-bottom: 10px;
    .rightgroup {
      width: 120px;
      float: right;;
      font-size: 14px;
      margin: auto;
      color: #333333;
    }
  }
}
.img {
  width: 50px;
  height: 50px;
  margin: auto 10px;

  img {
    width: 50px;
    height: 100%;
    display: inline-block;
  }
}
.box {

  .search {
    position: absolute;
    top: 25px;
    width: 100%;
  font-size: 14px;
    z-index: 2;

  }
}
  .icon {
        position: absolute;
    top: 3px;
    right: 15px;
    width: 20px;
    height: 20px;
    font-size: 25px;
    color: #fff;
  }
.van-search {
  width: 310px;
  background-color: #fff;
  padding: 0 10px ;
  border-radius: 3px;
  margin-left: 20px;
  color: #333;
}
.van-search__content {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    padding-left: 12px;
    background-color: #fff;
    border-radius: 2px;
    font-size: 13px !important;
}

/deep/input, button, textarea {
    color: inherit;
    font: inherit;
    font-size: 13px;
    color: #9c9fa1;
}
</style>
